B_1 = [2, 16, 44, 56, 32];
A_1 = [3, 3, -15, 18, -12];
[R_1, P_1, K_1] = residuez(B_1, A_1);

figure(1)
B_2_1 = [0, 2, -1.6, -0.9];
A_2_1 = [1, -2.5, 1.96, -0.48];
zplane(B_2_1, A_2_1);
legend("零点", "极点");
title("问题2（1）")

figure(2)
B_2_2 = [0, 0, 0, 1, -1];
A_2_2 = [1, -0.9, -0.65, 0.873, 0];
zplane(B_2_2, A_2_2);
legend("零点", "极点");
title("问题2（2）")

figure(3)
B_3 = [1, 0, 0];
A_3 = [1, -3 / 4, 1 / 8];
[H, w] = freqz(B_3, A_3, 400, "whole");
H_m = abs(H);
H_p = angle(H);
subplot(211)
plot(w, H_m);
xlabel("角度（rad/s）");
ylabel("幅度");
title("问题3，幅频特性");
subplot(212);
plot(w, H_p);
xlabel("角度（rad/s）");
ylabel("相位");
title("问题3，相频特性");

A_4 = zeros(1, 9);
A_4(1, 1) = 1;
A_4(1, 9) = -0.9;
B_4 = zeros(1, 9);
B_4(1, 1) = 1;
B_4(1, 9) = -1;
figure(4);
zplane(B_4, A_4);
legend("零点", "极点");
title("问题4（1）");

figure(5);
[H_4, w_4] = freqz(B_4, A_4, 400, "whole");
H_m_4 = abs(H_4);
H_p_4 = angle(H_4);
subplot(211);
plot(w_4, H_m_4);
xlabel("角度（rad/s）");
ylabel("幅度");
title("问题4，幅频特性");
subplot(212);
plot(w_4, H_p_4);
xlabel("角度（rad/s）");
ylabel("相位");
title("问题4，相频特性");

figure(6);
a_1 = [1, 0];
b_1 = [1, 0.8];
[y, Fs] = audioread("motherland.wav");
samples = [Fs, 2 * Fs + 1];
second = Fs:2 * Fs + 1;
[y, Fs] = audioread("motherland.wav", samples);
filted = filter(b_1, a_1, y)';
plot(second, filted);
sound(filted, Fs);
